package com.lb.lock.mapper;

import com.lb.lock.po.UsrUserAccount;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

public interface UsrUserAccountMapper extends Mapper<UsrUserAccount> {

    @Update("<script> update usr_user_account set\n" +
            "        version = version+1" +
            " <if test=\"userId != null\">\n" +
            "            ,user_id = #{userId}\n" +
            "        </if>\n" +
            "        <if test=\"balance != null\">\n" +
            "            ,balance = #{balance}\n" +
            "        </if>\n" +
            "        <if test=\"createBy != null\">\n" +
            "            ,create_by = #{createBy}\n" +
            "        </if>\n" +
            "        <if test=\"createTime != null\">\n" +
            "            ,create_time = #{createTime}\n" +
            "        </if>\n" +
            "        <if test=\"modifyBy != null\">\n" +
            "            ,modify_by = #{modifyBy}\n" +
            "        </if>\n" +
            "        <if test=\"modifyTime != null\">\n" +
            "           ,modify_time = #{modifyTime}\n" +
            "        </if>"+
            " where\n" +
            "         version=#{version}"+
            " <if test=\"id != null\">\n" +
            "           and  id=#{id}\n" +
            "        </if>\n" +
            "        <if test=\"userId != null\">\n" +
            "          and user_id=#{userId}\n" +
            "        </if>"+
            "</script>")
    public boolean updateAccount(UsrUserAccount userAccount) throws Exception;

    @Select("select\n" +
            "        *\n" +
            "        from\n" +
            "          usr_user_account\n" +
            "        where\n" +
            "          user_id=#{userId}")
    public UsrUserAccount getUserAccountByUserId(Long userId) throws Exception;
}
